<template>
  <el-form>
    <el-form-item label="旧密码" label-width="80px">
      <el-input type="password" v-model="old_password" placeholder="请输入旧密码" />
    </el-form-item>
    <el-form-item label="新密码" label-width="80px">
      <el-input type="password" v-model='new_password' placeholder="请输入新密码" />
    </el-form-item>
    <el-form-item label="再输一次" label-width="80px">
      <el-input type="password" v-model="new_password_again" placeholder="请输入再输一次" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { changepassword } from '@/api/configuration'
import { MessageBox, Message } from 'element-ui'
export default {
  data() {
    return {
      old_password: '',
      new_password: '',
      new_password_again: ''
    }
  },
  methods: {
    submit() {

      if(this.new_password == this.new_password_again){
        var data = {
          old_password: this.old_password,
          new_password: this.new_password,
          new_password_again: this.new_password_again
        }
        changepassword(data).then(res=>{
          console.log(res)
          this.$message({
            message: res.msg,
            type: 'success',
            // duration: 1000
          })
          this.$router.push(`/login?redirect=${this.$route.fullPath}`);
        })
      }else{
         this.$message({
          message: '两次输入密码不一致',
          type: 'warning',
          // duration: 1000
        })
      }
     
    }
  }
}
</script>
